<!DOCTYPE html>
<html lang="en" class="dark">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css" />
    <link
      rel="stylesheet"
      href="//unpkg.com/element-plus/theme-chalk/dark/css-vars.css"
    />
    <script src="./vue.js"></script>
    <script src="//unpkg.com/element-plus"></script>
    <script src="//unpkg.com/element-plus/dist/locale/zh-cn"></script>
    <script src="./axios.min.js"></script>
    <style>
      .el-pagination.is-background .btn-next.is-active,
      .el-pagination.is-background .btn-prev.is-active,
      .el-pagination.is-background .el-pager li.is-active {
        background-color: orange;
      }
      .el-pagination.is-background .btn-next,
      .el-pagination.is-background .btn-prev,
      .el-pagination.is-background .el-pager li:hover {
        color: orange;
      }
      li {
        margin: 5px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div>
        <el-button
          v-for="(item,index) in bangMenu.slice(0,3)"
          @click="bangIndex=index,miniBangIndex=0,checkoutBang()"
          :type="index==bangIndex?'primary':''"
          >{{item.name}}</el-button
        >
      </div>
      <ul v-if="bangMenu.length">
        <li v-for="(item,index) in bangMenu[bangIndex].list">
          <el-button
            :type="index==miniBangIndex?'primary':''"
            @click="miniBangIndex=index,checkoutBang()"
            >{{item.name}}</el-button
          >
        </li>
      </ul>
      <!-- 列表 -->
      <ul>
        <li v-for="item in musicList">
          {{item.name}} --- <span v-if="item.hasmv">mv</span>
        </li>
      </ul>
      <!-- 分页 -->
      <el-pagination
        layout="prev, pager, next"
        :total="total"
        background
        :page-size="20"
        v-model:current-page="queryObj.pn"
      ></el-pagination>
      <pre>{{queryObj}}</pre>
    </div>
  </body>
  <script>
    let app = Vue.createApp({
      data() {
        return {
          queryObj: {
            sourceid: 93, //榜id
            pn: 1, //页码
            rn: 20, //一页多少条
          },
          // 排行榜集合
          bangMenu: [],
          bangIndex: 0, //选中的大榜索引
          miniBangIndex: 0, //选中的小榜索引
          musicList: [], //歌曲列表数据
          total: 0, //总条数
        };
      },
      created() {
        this.getBangMenu(); //创建完毕 请求初始数据
      },
      methods: {
        async getBangMenu() {
          let { data } = await axios.get(
            "http://localhost:6060/api/www/bang/bang/bangMenu?httpsStatus=1&reqId=1c668620-76c5-11ee-aecf-897662e75ada&plat=web_www"
          );
          this.bangMenu = data.data;
          this.checkoutBang();
        },
        // 切换榜
        checkoutBang() {
          this.queryObj.bangId =
            this.bangMenu[this.bangIndex].list[this.miniBangIndex].sourceid;
        },
        // 请求列表数据
        async getMusicList(val) {
          let { data } = await axios.get(
            "http://localhost:6060/api/www/bang/bang/musicList?httpsStatus=1&reqId=1c8558c0-76c5-11ee-aecf-897662e75ada&plat=web_www&from=",
            {
              params: val,
            }
          );
          this.musicList = data.data.musicList;
          this.total = data.data.num * 1;
        },
      },
      watch: {
        queryObj: {
          deep: true,
          handler(val) {
            // 参数对象变化  请求最新数据
            console.log("请求数据", JSON.stringify(this.queryObj));
            this.getMusicList(val);
          },
        },
      },
    });

    // mounted  beforeUnmount
    app = app
      .use(ElementPlus, {
        locale: ElementPlusLocaleZhCn,
      })
      .mount("#app");
  </script>
</html>
